home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1997 September
/
Macworld (1997-09).dmg
/
Serious Software
/
Cherwell Scientific Demos
/
pro Fit
/
pro Fit 5.0 demo (fpu).sea
/
pro Fit 5.0 demo (fpu)
/
External Modules
/
External modules sources
/
C
/
lissajous.c
< prev
next >
Wrap
Text File
|
1996-04-21
|
4KB
|
122 lines
/***************************************************************************************/
/* Lissajous.c */
/* */
/* Version 26.9.94 */
/***************************************************************************************/
#include "proFit_interface.h"
#include <math.h> //for cos and sin
/***************************************************************************************/
void SetUp ( short* const moduleKind, /* set moduleKind to isFunction or isProgram */
Str255 name, /* the name of the program or function (pascal string) */
long* const requiredGlobals, /* the number of bytes to be allocated in ExtModulesParamBlock.globals */
/* set requiredGlobals to 0 if you don't use this feature */
ExtModulesParamBlock* pb) /* the complete parameter block passed by pro Fit to the */
/* routines defined in this file. In most cases it can be ignored */
/* SetUp is called once when the external module is linked to proFit */
{
*moduleKind=isProgram; /* we define a program */
SetPascalStr(name,"\pLissajous",255); /* its name */
*requiredGlobals = 0; /* we don't need global data */
}
/***************************************************************************************/
void InitializeProg (ExtModulesParamBlock* pb)
/* Can be left emtpy if not needed. */
/* called when the external module is linked to proFit after SetUp was called */
/* can be used to inititialize global variables, etc. */
{
/* initialize default values: */
pb->v[1] = 3; /* the frequency along x */
pb->v[2] = 4; /* the frequency along y */
pb->v[3] = 0.5; /* the step width */
pb->v[4] = 300; /* the number of points */
}
/***************************************************************************************/
#define H_ZOOM 200.0
#define V_ZOOM 200.0
#define H_OFFSET 280.0
#define V_OFFSET 220.0
void Run(ExtModulesParamBlock* pb)
/* pro Fit calls this function when the name of the program is chosen from the */
/* Run Program submenu in the menu Calc */
{
double ex1=pb->v[1], ex2=pb->v[2], /* buffers for input */
ex3=pb->v[3], ex4=pb->v[4]; /* default values are stored in v[..] */
InputRec r; /* dto */
int i;
double angle;
// get the parameters from user, for this we prepare the inputRec r */
r[0].x = &ex1;
r[0].s = "\pFrequency x";
r[1].x = &ex2;
r[1].s = "\pFrequency y";
r[2].x = &ex3;
r[2].s = "\pStep [rad]";
r[3].x = &ex4;
r[3].s = "\pNumber of points";
if (InputBox(4, &r)) return;
if (ex4 > 32767) /* make sure ex4 can be cast to an integer */
ex4 = 32767;
else if (ex4 < 0)
ex4 = 0;
pb->v[1] = ex1; /* defaults for next time */
pb->v[2] = ex2;
pb->v[3] = ex3;
pb->v[4] = ex4;
/* start drawing the curve: */
GrMoveTo(H_ZOOM+H_OFFSET, V_OFFSET); /* move to the starting point */
OpenPolygon(0,0);
angle = 0;
for (i = 1;i<= ex4;i++)
{ GrLineTo( H_ZOOM*cos(ex1 * angle)+H_OFFSET,
V_ZOOM*sin(ex2 * angle)+V_OFFSET);
angle += ex3;
} /* for i */
ClosePolygon();
} /* run */
/***************************************************************************************/
void CleanUp (ExtModulesParamBlock* pb)
/* called when the function or program is removed from pro Fit's menus */
/* in most cases, this function can be empty */
{
}
/***************************************************************************************/
/* for functions, not used here: */
/***************************************************************************************/
void InitializeFunc (Boolean* const hasDerivatives, Str255 descr1stLine, Str255 descr2ndLine,
short* const numberOfParams, DefaultParamInfo* const a0, ExtModulesParamBlock* pb)
{}
void Func ( double x, ParamArray a, double* const y, ExtModulesParamBlock* pb)
{}
void Derivatives(double x, ParamArray a, ParamArray dyda, ExtModulesParamBlock* pb)
{}
short Check(short paramNo, DefaultParamInfo* const a0, ExtModulesParamBlock* pb)
{return ok;}
void First (ParamArray a, ExtModulesParamBlock* pb)
{}
void Last (ExtModulesParamBlock* pb)
{}